﻿<?php 
include("conn.php");
mysql_query('SET NAMES UTF8'); 

		class MyPrizeBean
		{
			public $title;
			public $price;
			public $images;
			public $yuanjia;
			public $goodsid;
			public $reply;
			public $xihuan;
			public $summary;
		    public $xiaoliang;
		    public $code;

			function __construct($title,$price,$images,$yuanjia,$goodsid,$reply,$xihuan,$summary,$xiaoliang,$code)
			{
				$this->title      = $title;
				$this->price = $price;
				$this->images     = $images;
				$this->yuanjia      = $yuanjia;
				$this->goodsid    = $goodsid;
				$this->reply    = $reply;
				$this->xihuan    = $xihuan;
				$this->summary    = $summary;
				$this->xiaoliang   = $xiaoliang;
				$this->code   = $code;
			}
		}

	   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
		    $theta = $longitude1 - $longitude2;
		    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
		    $miles = acos($miles);
		    $miles = rad2deg($miles);
		    $miles = $miles * 60 * 1.1515;
		    $kilometers = $miles * 1.609344;
		    return compact('kilometers'); 
       }

		if($_REQUEST['page']!=""){
			$de=$_REQUEST['page']*$_REQUEST['pagesize'];
			$size=$_REQUEST['pagesize'];
		}else{
			$de=0;
			$size=5;
		}

		if($_REQUEST[state]==1){
		   $desc= "xiaoliang desc";
		}else if($_REQUEST[state]==2){
		   $desc= "price desc";
		}else if($_REQUEST[state]==3){
		    $desc= "price";
		}else if($_REQUEST[state]==4){
			$desc= "likes desc";
		}else if($_REQUEST[state]==5){
		    $desc= "pingfen desc";
		}
		else if($_REQUEST[state]==6){
		    $desc= "pingfen";
		}else {
		    $desc= "goodsid desc";
		}


	if ($_REQUEST[cityid]!='') {
		$query="select * from goods where shopid in (select shopid from shop where city='".$_REQUEST[cityid]."') and  title like '".$_REQUEST['keywords']."%'"; 
	}else{
		$query="select * from goods where  title like '".$_REQUEST['keywords']."%'"; 
	}

	$query.=" order by  $desc limit $de,$size";
	$rert=mysql_query($query);
	$prize = array();

	while($rowf = mysql_fetch_array($rert)){
        $ime = $rowf[images];
		$de = array();
		$de = explode("," ,$ime);
		$images = $de[1];

	   if(strlen($rowf['title'])>14){
			$NAMES=mb_substr($rowf['title'], 0,14,"UTF-8");
		}
		else{
			$NAMES=$rowf['title'];
		}
		
		if(strlen($rowf['summary'])>30){
			$summarys=mb_substr($rowf['summary'], 0,30,"UTF-8");
		}else{
			$summarys=$rowf['summary'];
		}
	
	   $prize[] = new MyPrizeBean($NAMES,$rowf['price'],$images,$rowf['yuanjia'],$rowf['goodsid'],$rowf['replynumber'],$rowf['xihuan'],$summarys,$rowf['xiaoliang'],200);
		
	}

$arr = array('code' => 200, 'msg' =>'查询商品或商家成功', 'data' => $prize);
echo json_encode($arr);


?>